package com.ape.mapsa.produccion.dao;

import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.ape.mapsa.produccion.model.ConfProdScrap;
import com.ape.mapsa.produccion.model.Confeccion;
import com.ape.mapsa.produccion.model.ExtProdScrap;
import com.ape.mapsa.produccion.model.Extrusion;
import com.ape.mapsa.produccion.model.ImpProdScrap;
import com.ape.mapsa.produccion.model.Impresion;

@Repository
public class ProdScrapDAOImpl extends GenericDAOImpl<Object, Long> implements ProdScrapDAO {

	@SuppressWarnings("unchecked")
	@Override
	public List<ExtProdScrap> getExtrusionScrap(Extrusion extrusion) {
		return sessionFactory.getCurrentSession().createCriteria(ExtProdScrap.class).add(Restrictions.eq("extrusion", extrusion))
				.add(Restrictions.eq("state", 1)).list();
	}

	@Override
	public void saveExtScrap(ExtProdScrap scrap) {
		sessionFactory.getCurrentSession().save(ExtProdScrap.class.getName(), scrap);
	}

	@Override
	public void updateExtScrap(ExtProdScrap scrap) {
		sessionFactory.getCurrentSession().update(ExtProdScrap.class.getName(), scrap);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ImpProdScrap> getImpresionScrap(Impresion impresion) {
		return sessionFactory.getCurrentSession().createCriteria(ImpProdScrap.class).add(Restrictions.eq("impresion", impresion))
				.add(Restrictions.eq("state", 1)).list();
	}

	@Override
	public void saveImpScrap(ImpProdScrap scrap) {
		sessionFactory.getCurrentSession().save(ImpProdScrap.class.getName(), scrap);
	}

	@Override
	public void updateImpScrap(ImpProdScrap scrap) {
		sessionFactory.getCurrentSession().update(ImpProdScrap.class.getName(), scrap);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ConfProdScrap> getConfeccionScrap(Confeccion confeccion) {
		return sessionFactory.getCurrentSession().createCriteria(ConfProdScrap.class).add(Restrictions.eq("confeccion", confeccion))
				.add(Restrictions.eq("state", 1)).list();
	}

	@Override
	public void saveConfScrap(ConfProdScrap scrap) {
		sessionFactory.getCurrentSession().save(ConfProdScrap.class.getName(), scrap);

	}

	@Override
	public void updateConfScrap(ConfProdScrap scrap) {
		sessionFactory.getCurrentSession().update(ConfProdScrap.class.getName(), scrap);
	}

}
